Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/Exceptions.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 4.04 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.common.util

Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CancellationException

Tff7b72object T56d364Exceptions Tb4b4b4{
T8b949e/** Set by the application to provide a custom crash reporting implementation. */
Tff7b72var Te6edf3reporterTb4b4b4: Tb4b4b4(Tb4b4b4(Te6edf3ThrowableTb4b4b4, Tffa657String?Tb4b4b4, Tffa657String?Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4)Tff7b72? Tff7b72= Tff7b72null

T8b949e/**
* Report an exception to the configured reporter (if any) after logging it.
*
* @param exception The exception to report.
* @param tag An optional tag for the report.
* @param message An optional message providing context.
*/
Tff7b72fun Td2a8ffreportTb4b4b4(Te6edf3exceptionTb4b4b4: Te6edf3ThrowableTb4b4b4, Te6edf3tagTb4b4b4: Tffa657String? Tff7b72= Tff7b72nullTb4b4b4, Te6edf3messageTb4b4b4: Tffa657String? Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
T8b949e// Log locally first
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3exceptionTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffExceptions.report: Tffd700${Te6edf3tag Tff7b72?: Ta5d6ff"Te6edf3noTff7b72-Te6edf3tagTa5d6ff"Tffd700}Ta5d6ff Tffd700${Te6edf3message Tff7b72?: Ta5d6ff"Te6edf3noTff7b72-Te6edf3messageTa5d6ff"Tffd700}Ta5d6ff" Tb4b4b4}
Te6edf3reporterTff7b72?.Te6edf3invokeTb4b4b4(Te6edf3exceptionTb4b4b4, Te6edf3tagTb4b4b4, Te6edf3messageTb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/** Wraps and discards exceptions, optionally logging them. */
Tff7b72fun Td2a8ffignoreExceptionTb4b4b4(Te6edf3silentTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4, Te6edf3innerTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3exTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3silentTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffIgnoring exceptionTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

T8b949e/** Suspend-compatible variant of [ignoreException]. Re-throws [CancellationException]. */
Tff7b72suspend Tff7b72fun Td2a8ffignoreExceptionSuspendTb4b4b4(Te6edf3silentTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4, Te6edf3innerTb4b4b4: Te6edf3suspend Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3CancellationExceptionTb4b4b4) Tb4b4b4{
Tff7b72throw Te6edf3e
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3exTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3silentTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3exTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffIgnoring exceptionTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Wraps and discards exceptions, but reports them to the crash reporter before logging. Use this for operations that
* should not crash the process but are still unexpected.
*/
Tff7b72fun Td2a8ffexceptionReporterTb4b4b4(Te6edf3innerTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3innerTb4b4b4(Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3exTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3ExceptionsTb4b4b4.Te6edf3reportTb4b4b4(Te6edf3exTb4b4b4, Ta5d6ff"Ta5d6ffexceptionReporterTa5d6ff"Tb4b4b4, Ta5d6ff"Ta5d6ffUncaught ExceptionTa5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Like [kotlin.runCatching], but re-throws [CancellationException] to preserve structured concurrency. Use this instead
* of [runCatching] in coroutine contexts.
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72inline Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffsafeCatchingTb4b4b4(Te6edf3blockTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4)Tb4b4b4: Te6edf3ResultTff7b72<Te6edf3TTff7b72> Tff7b72= Tff7b72try Tb4b4b4{
Te6edf3ResultTb4b4b4.Te6edf3successTb4b4b4(Te6edf3blockTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3CancellationExceptionTb4b4b4) Tb4b4b4{
Tff7b72throw Te6edf3e
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3ResultTb4b4b4.Te6edf3failureTb4b4b4(Te6edf3eTb4b4b4)
Tb4b4b4}

T8b949e/** Like [kotlin.runCatching] receiver variant, but re-throws [CancellationException]. */
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72inline Tff7b72fun Tff7b72<Te6edf3TTb4b4b4, Te6edf3RTff7b72> Te6edf3TTb4b4b4.Td2a8ffsafeCatchingTb4b4b4(Te6edf3blockTb4b4b4: Te6edf3TTb4b4b4.Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3RTb4b4b4)Tb4b4b4: Te6edf3ResultTff7b72<Te6edf3RTff7b72> Tff7b72= Tff7b72try Tb4b4b4{
Te6edf3ResultTb4b4b4.Te6edf3successTb4b4b4(Te6edf3blockTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3CancellationExceptionTb4b4b4) Tb4b4b4{
Tff7b72throw Te6edf3e
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3ResultTb4b4b4.Te6edf3failureTb4b4b4(Te6edf3eTb4b4b4)
Tb4b4b4}

T8b949e/**
* Like [safeCatching] but also catches JVM [Error]s (e.g. [ExceptionInInitializerError] raised by compose-resources'
* lazy skiko initialization on the desktop JVM test classpath). Still re-throws [CancellationException] so structured
* concurrency is preserved. Use when the block invokes code whose failure modes include static-initializer errors and
* the caller only needs a best-effort fallback.
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72inline Tff7b72fun Tff7b72<Te6edf3TTff7b72> Td2a8ffsafeCatchingAllTb4b4b4(Te6edf3blockTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3TTb4b4b4)Tb4b4b4: Te6edf3ResultTff7b72<Te6edf3TTff7b72> Tff7b72= Tff7b72try Tb4b4b4{
Te6edf3ResultTb4b4b4.Te6edf3successTb4b4b4(Te6edf3blockTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3CancellationExceptionTb4b4b4) Tb4b4b4{
Tff7b72throw Te6edf3e
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3tTb4b4b4: Te6edf3ThrowableTb4b4b4) Tb4b4b4{
Te6edf3ResultTb4b4b4.Te6edf3failureTb4b4b4(Te6edf3tTb4b4b4)
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s